<?php
if (!defined('BASEPATH')) {
	exit('No direct script access allowed');
}

if (!function_exists('remote_filesize')) {
	function remote_filesize($url){
    # Get all header information
    $data = get_headers($url, true);
    # Look up validity
    if (isset($data['Content-Length']))
        # Return file size
        return (int) $data['Content-Length'];
	}
}

if (!function_exists('human_filesize')) {
	function human_filesize($bytes, $decimals = 2) {
    $size = array(' B',' kB',' MB',' GB',' TB',' PB',' EB',' ZB',' YB');
    $factor = floor((strlen($bytes) - 1) / 3);
    return sprintf("%.{$decimals}f", $bytes / pow(1024, $factor)) . @$size[$factor];
	}
}

if (!function_exists('get_remote_filesize')) {
	function get_remote_filesize($url = ''){
		if($url != ''){
			$file_size = human_filesize(remote_filesize($url));
		}else{
			$file_size = 'URL tidak ada';
		}

		return $file_size;
	}
}

if (!function_exists('get_filesize')) {
	function get_filesize($string = ''){
		if($string != ''){
			$filesize = human_filesize(filesize($string));
		}else{
			$filesize = 'Nama file tidak dicantumkan';
		}

		return $filesize;
	}
}